package com.iplant.ams.service.basicenum.dms.scada;


import com.iplant.base.po.enums.BaseEnum;
import com.iplant.base.utils.general.StringUtils;

/**
 * 采集模式
 */
public enum DMSDataTypes implements BaseEnum {
    /**
     * 默认
     */
    Default(0, "默认"),

    /**
     * 布尔
     */
    Bool(1, "布尔"),
    /**
     * 短整型
     */
    Int(2, "短整型"),
    /**
     * 字符串
     */
    String(3, "字符串"),
    /**
     * 浮点
     */
    Float(4, "浮点"),
    /**
     * 双浮点
     */
    Double(5, "双浮点"),
    /**
     * 长整型
     */
    Int32(6, "长整型"),
    /**
     * 日期时间
     */
    DateTime(7, "日期时间"),
    /**
     * 布尔数组
     */
    BoolArray(8, "布尔数组"),
    /**
     * 字节
     */
    Byte(9, "字节"),
    /**
     * 日期
     */
    Date(9, "日期"),
    /**
     * 时间
     */
    Time(9, "时间");

    private int value;
    private String label;
    private String remark = "";

    DMSDataTypes(int value, String label) {
        this.value = value;
        this.label = label;
    }

    public static DMSDataTypes getEnumType(int val) {
        for (DMSDataTypes type : DMSDataTypes.values()) {
            if (type.getValue() == val) {
                return type;
            }
        }
        return Default;
    }

    public static DMSDataTypes getEnumTypeObject(Object val) {

        return getEnumType(StringUtils.parseInt(val));
    }

    @Override
    public int getValue() {
        return value;
    }

    @Override
    public void setValue(int value) {
        this.value = value;
    }

    @Override
    public String getLabel() {
        return label;
    }

    @Override
    public void setLabel(String label) {
        this.label = label;
    }

    @Override
    public String getRemark() {
        return remark;
    }

    @Override
    public void setRemark(String remark) {
        this.remark = remark;
    }


    public String GetMysqlTypeString() {

        return GetMysqlTypeString(0);
    }

    public String GetMysqlTypeString(int wLength) {
        String wDBString = "varchar(20)";
        if (wLength <= 0)
            wLength = 20;
        switch (this) {
            case Default:
                break;
            case Bool:
                wDBString = "tinyint(1)";
                break;
            case Int:
                wDBString = "int";
                break;
            case String:
                wDBString = StringUtils.Format("varchar({0})", wLength);
                break;
            case Float:
                wDBString = "float";
                break;
            case Double:
                wDBString = "double";
                break;
            case Int32:
                wDBString = "int";
                break;
            case DateTime:
                wDBString = "datetime(3)";
                break;
            case BoolArray:
                wDBString = "int";
                break;
            case Byte:
                wDBString = "int";
                break;
            case Date:
                wDBString = "Date";
                break;
            case Time:
                wDBString = "Time(3)";
                break;
            default:
                break;
        }
        return wDBString;
    }

    public String GetMysqlTypeStringObject(Object wLength) {
        return GetMysqlTypeString(StringUtils.parseInt(wLength));
    }

    public static String GetMysqlTypeString(int wTypeValue, int wLength) {
        DMSDataTypes wDMSDataTypes = DMSDataTypes.getEnumType(wTypeValue);

        return wDMSDataTypes.GetMysqlTypeString(wLength);
    }


    public String GetMysqlDefaultString() {
        String wDefaultString = "''";

        switch (this) {
            case Default:
                break;
            case Bool:
            case Int:
            case Float:
            case Double:
            case Int32:
            case BoolArray:
            case Byte:
                wDefaultString = "'0'";
                break;
            case String:
                break;
            case DateTime:
                wDefaultString = " CURRENT_TIMESTAMP(3) ";
                break;
            case Date:
                wDefaultString = "'2000-01-01'";
                break;
            case Time:
                wDefaultString = "'00:00:00.000'";
                break;
            default:
                break;
        }
        return wDefaultString;
    }

    public static String GetMysqlDefaultString(int wTypeValue) {
        DMSDataTypes wDMSDataTypes = DMSDataTypes.getEnumType(wTypeValue);


        return wDMSDataTypes.GetMysqlDefaultString();
    }


}
